package utils;


import android.os.SystemClock;
import android.view.View;

public abstract class OnMultipleClickListener implements View.OnClickListener {

    private int mTimes;
    private long[] mHits;

    /**
     * @param times 点击次数
     */
    public OnMultipleClickListener(int times) {
        this.mTimes = times;
        this.mHits = new long[times];
    }

    @Override
    public void onClick(View v) {
        System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);
        mHits[mHits.length - 1] = SystemClock.uptimeMillis();
        if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
            onMultipleClick(v);
            mHits = null;
            mHits = new long[mTimes];
        }
    }

    public abstract void onMultipleClick(View v);

}
